﻿layui.use(['upload', 'element', 'layer', 'table', 'dropdown', 'form', 'laydate'], function () {
    var $ = layui.jquery
        , upload = layui.upload
        , element = layui.element
        , layer = layui.layer
        , dropdown = layui.dropdown
        , laydate = layui.laydate
        , form = layui.form
        , table = layui.table;
    abc = $("#jbxxid").val() === '' ? '' : '?Jbxxid=' + $("#jbxxid").val();
    //招录信息保存
    layui.use('table', function () {
        table.render({
            elem: '#tablezlxx'
            , url: '../Zlxxes/ShowZlxx' + abc //数据接口
            , cols: [[ //表头
                { field: 'lyscrouce', title: '录用来源', width: 125, minWidth: 125 }
                , { field: 'remark', title: '备注', width: 125, minWidth: 125 }
                , { field: 'rz', title: '面试人员', width: 125, minWidth: 125 }
                , { field: 'rcdjb', title: '《人才登记表》', width: 125, minWidth: 125, templet: proofPicturercdjb }
                , { field: 'msb', title: '《面试评定表》', width: 125, minWidth: 125, templet: proofPicturemsb }
                , { fixed: 'yesorno', title: '是否背景调查', width: 125, minWidth: 125, toolbar: '#yesorno'}
                , { field: 'bjdc', title: '背景调查报告', width: 137, minWidth: 137 ,templet: function (d) {

                        if (d.bjdc != null && d.bjdc != "" && d.bjdc != "[]") {
                            let str = [];

                            for (i = 0; i < d.bjdc.length; i++) {
                                if (d.bjdc[i] != "?") {
                                    str += d.bjdc[i];

                                } else {
                                    str += "\n";
                                }
                            }
                            return str;


                        }

                    } }
                , { field: 'result', title: '薪酬评定结果', width: 125, minWidth: 125, templet: function (d) {

                        if (d.result != null && d.result != "" && d.result != "[]") {
                            let str = [];

                            for (i = 0; i < d.result.length; i++) {
                                if (d.result[i] != "?") {
                                    str += d.result[i];

                                } else {
                                    str += "\n";
                                }
                            }
                            return str;
                        }

                    }  }
                , { field: 'resultBz', title: '《薪酬评定表》', width: 125, minWidth: 125, templet: proofPicturebz }
            ]]
            , done: function (res) {
                if (res.data[0].lyscrouce != "关系推荐") {
                    $("[data-field='remark']").css('display', 'none');
                }
                if (res.data[0].bjdc == "没有背景调查") {
                    $("[data-field='bjdc']").css('display', 'none');
                    $("#yesyes").hide();
                } else {
                    $("#nono").hide();
                }
            }
        });        
    });
    //人才测评保存
    layui.use('table', function () {
        var $ = layui.jquery

        table.render({
            elem: '#testRccp'
            , url: '../Rccps/ShowRccp' + abc
            , cols: [[
                { field: 'CpTool', width: 128, title: '测评工具', width: 125, minWidth: 125 }
                , { field: 'CpType', width: 128, title: '测评类型', width: 125, minWidth: 125 }
                , { field: 'DateTime', width: 120, title: '测评时间', width: 110, minWidth: 110 }
                , { field: 'CpResult', width: 180, title: '测评结果', width: 440, minWidth: 440, templet: function (d) {
                        if (d.CpResult != null && d.CpResult != "" && d.CpResult != "[]") {
                            let str = [];

                            for (i = 0; i < d.CpResult.length; i++) {
                                if (d.CpResult[i] != "?") {
                                    str += d.CpResult[i];

                                } else {
                                    str += "\n";
                                }
                            }
                            return str;
                        }
                        
                        }
                    }
                , { field: 'CpFile', width: 180, title: '测评报告', width: 125, minWidth: 125, templet: proofPicturecp }
            ]]
        });
    });

    //人才盘点保存
    layui.use('table', function () {

        table.render({
            elem: '#testRcpd'
            , url: '../Rcpd/ShowRcpd' + abc
            , cols: [[
                { field: 'DateTime', width: 120, title: '盘点时间', width: 125, minWidth: 125 }
                , { field: 'PdName', width: 100, title: '盘点项目', width: 125, minWidth: 125 }
                , {
                    field: 'PdResult', width: 180, title: '盘点结果', width: 460, minWidth: 460, templet: function (d) {
                        if (d.PdResult != null && d.PdResult != "" && d.PdResult != "[]") {
                            let str = [];

                            for (i = 0; i < d.PdResult.length; i++) {
                                if (d.PdResult[i] != "?") {
                                    str += d.PdResult[i];

                                } else {
                                    str += "\n";
                                }
                            }
                            return str;
                        }

                    }
                }
            ]]
        });
    });
});

//显示与隐藏其他
layui.use('form', function () {
    var form = layui.form;
    //监听提交
    form.on('select(zp)', function (data) {
        var value = data.value;
        if (value == "关系推荐") {
            $("#qita").show();
            document.getElementById("")
        } else {
            $("#qita").hide();
        }
    });
    form.on('submit(formData)', function (data) {
        layer.msg(JSON.stringify(data.field));
        return false;
    });
});

//是否背景调查
layui.use('form', function () {
    var form = layui.form;

    form.on('radio(bjdc)', function (data) {

        if ($('#IsbjdcPurchased input[name="dc"]:checked ').val() == "否") {
            $("#yesbjdc").hide();
            $("textarea[name=Bjdc]").val("没有背景调查");
        }
        else {
            $("#yesbjdc").show();
            $("textarea[name=Bjdc]").val("背调人员：\n背调时间：\n背调情况：");
        }
        form.render();
    });
});

//测评类型
layui.use('form', function () {
    var form = layui.form;
    //var valuetype = document.getElementById("cptype").valueof();
    //var _value = $("#cptype").val();
    form.on('select(cptype)', function (data) {
        var valuetype = data.value;
        if (valuetype == "锐途测评") {
            $("#v5").show();
            $("#v1").show();
            $("#v2").hide();
            $("#v3").hide();
            $("#v4").hide();
        } else if (valuetype == "管理人员外部招聘测评-中层通用" || valuetype == "管理人员外部招聘测评-销售" || valuetype == "管理人员外部招聘测评-财务" ||
            valuetype == "管理人员外部招聘测评-人力资源" || valuetype == "管理人员外部招聘测评-行政" || valuetype == "管理人员评估选拔测评-中层通用" ||
            valuetype == "管理人员评估选拔测评-销售" || valuetype == "管理人员评估选拔测评-财务" || valuetype == "管理人员评估选拔测评-人力资源" || valuetype == "管理人员评估选拔测评-行政") {
            $("#v2").show();
            $("#v5").show();
            $("#v1").hide();
            $("#v3").hide();
            $("#v4").hide();
        } else if (valuetype == "基层人员校园招聘-通用" || valuetype == "基层人员校园招聘-财务" || valuetype == "基层人员校园招聘-技术研发" || valuetype == "基层人员校园招聘-客户服务" ||
            valuetype == "基层人员校园招聘-营销" || valuetype == "基层人员校园招聘-职能支持类" || valuetype == "基层人员社会招聘-财务类" || valuetype == "基层人员社会招聘-客户服务类" ||
            valuetype == "基层人员社会招聘-销售类" || valuetype == "基层人员社会招聘-人力资源类" || valuetype == "基层人员社会招聘-行政类" || valuetype == "基层人员社会招聘-技术支持类" ||
            valuetype == "基层潜才测评-通用高潜") {
            $("#v3").show();
            $("#v4").show();
            $("#v1").hide();
            $("#v2").hide();
            $("#v5").hide();
        } else {
            $("#v1").hide();
            $("#v2").hide();
            $("#v3").hide();
            $("#v4").hide();
            $("#v5").hide();
        }
    });
    form.on('submit(formData)', function (data) {
        layer.msg(JSON.stringify(data.field));
        return false;
    });
});

function to() {

    if (document.getElementById("cptype").value == "锐途测评") {
        var a = document.getElementById('value1').value;
        var e = document.getElementById('value5').value;
        //var a = $("#value1").val();
        //var e = $("#value5").val();

        document.getElementById('allvalue').value = e + "\n" + a;

        var text = $("#allvalue").val();
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
        $("#allvalue").val(des);

    } else if (document.getElementById("cptype").value == "管理人员外部招聘测评-中层通用" || document.getElementById("cptype").value == "管理人员外部招聘测评-销售" || document.getElementById("cptype").value == "管理人员外部招聘测评-财务" ||
        document.getElementById("cptype").value == "管理人员外部招聘测评-人力资源" || document.getElementById("cptype").value == "管理人员外部招聘测评-行政" || document.getElementById("cptype").value == "管理人员评估选拔测评-中层通用" ||
        document.getElementById("cptype").value == "管理人员评估选拔测评-销售" || document.getElementById("cptype").value == "管理人员评估选拔测评-财务" || document.getElementById("cptype").value == "管理人员评估选拔测评-人力资源" || document.getElementById("cptype").value == "管理人员评估选拔测评-行政") {
        var b = document.getElementById('value2').value;
        var e = document.getElementById('value5').value;

        document.getElementById('allvalue').value = e + "\n" + b;
        var text = $("#allvalue").val();
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
        $("#allvalue").val(des);

    } else if (document.getElementById("cptype").value == "基层人员校园招聘-通用" || document.getElementById("cptype").value == "基层人员校园招聘-财务" || document.getElementById("cptype").value == "基层人员校园招聘-技术研发" || document.getElementById("cptype").value == "基层人员校园招聘-客户服务" ||
        document.getElementById("cptype").value == "基层人员校园招聘-营销" || document.getElementById("cptype").value == "基层人员校园招聘-职能支持类" || document.getElementById("cptype").value == "基层人员社会招聘-财务类" || document.getElementById("cptype").value == "基层人员社会招聘-客户服务类" ||
        document.getElementById("cptype").value == "基层人员社会招聘-销售类" || document.getElementById("cptype").value == "基层人员社会招聘-人力资源类" || document.getElementById("cptype").value == "基层人员社会招聘-行政类" || document.getElementById("cptype").value == "基层人员社会招聘-技术支持类" ||
        document.getElementById("cptype").value == "基层潜才测评-通用高潜") {
        var c = document.getElementById('value3').value;
        var d = document.getElementById('value4').value;

        document.getElementById('allvalue').value = d + "\n" + c;
        var text = $("#allvalue").val();
        var des = text.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>');
        $("#allvalue").val(des);
    } else if (document.getElementById("cptype").value == "高层领导力测评") {
        document.getElementById("allvalue").value = "高层领导力测评";
    } else if (document.getElementById("cptype").value == "360测评") {
        document.getElementById("allvalue").value = "360测评";
    }
}

function gettheUserldatas() {

    var lis = [];

    $.ajax({
        url: "/User/GetUserData",
        type: "post",
        async: false,
        success: function (datas) {

            lis = datas;
            console.log(lis);

        }
    })

    return lis;

}
   
function Del_rccp(id) {
    var data = form.val('rccp');
    $.ajax({
        url: "/Rccps/Del_rccp",    //后台数据请求地址
        type: "post",
        async: false,
        data: { "id": id },
        success: function (resut) {
            layer.msg(resut);
        }
    });
    return data;
}
function Del_rcpd(id) {
    var data = form.val('rcpd');
    $.ajax({
        url: "/Rcpd/Del_rcpd",    //后台数据请求地址
        type: "post",
        async: false,
        data: { "id": id },
        success: function (resut) {
            layer.msg(resut);
        }
    });
    return data;
}

function proofPicturercdjb(d) {
    var i, count = 0;
    var str = [], aaa = [];
    var proofPicture = d.rcdjb;
    if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
        return '';
    }
    if (proofPicture.length > 0) {
        str = d.rcdjb.split(",");
        for (i = 0; i < d.rcdjb.length; i++) {
            if (d.rcdjb[i] == ",") { count += 1; }
        }
        for (j = 0; j < count + 1; j++) {
            aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
        }

        return aaa;
    }
}
function proofPicturemsb(d) {
    var i, count = 0;
    var str = [], aaa = [];
    var proofPicture = d.msb;
    if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
        return '';
    }
    if (proofPicture.length > 0) {
        str = d.msb.split(",");
        for (i = 0; i < d.msb.length; i++) {
            if (d.msb[i] == ",") { count += 1; }
        }
        for (j = 0; j < count + 1; j++) {
            aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
        }
        
        return aaa;
    }
}
function proofPicturebz(d) {
    var proofPicture = d.resultBz;
    var i, count = 0;
    var str = [], aaa = [];
    if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
        return '';
    }
    if (proofPicture.length > 0) {
        str = proofPicture.split(",");
        for (i = 0; i < proofPicture.length; i++) {
            if (proofPicture[i] == ",") { count += 1; }
        }
        for (j = 0; j < count + 1; j++) {
            aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
        }

        return aaa;
    }
}
function proofPicturecp(d) {
    var proofPicture = d.CpFile;
    var i, count = 0;
    var str = [], aaa = [];
    if ('' == proofPicture || null == proofPicture || undefined == proofPicture) {
        return '';
    }
    if (proofPicture.length > 0) {
        str = proofPicture.split(",");
        for (i = 0; i < proofPicture.length; i++) {
            if (proofPicture[i] == ",") { count += 1; }
        }
        for (j = 0; j < count + 1; j++) {
            aaa += '<a class="layui-blue" href="../UploadFiles/' + str[j] + '" target="_blank">' + str[j] + '</a><br/>';
        }

        return aaa;
    }
}